package com.keqing.controller;

import com.ganyu.domain.ResponseResult;
import com.ganyu.domain.entity.Menu;
import com.ganyu.service.impl.MenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * DATA: 2022/9/30
 * Author: 晨夕
 */
@RestController
@RequestMapping("/system/menu")
public class AdminMenuController {

    @Autowired
    private MenuServiceImpl menuServiceImpl;

    @GetMapping("/list")
    public ResponseResult getMenuList(String menuName,String status){
        return menuServiceImpl.getMenuList(menuName,status);
    }
    @PreAuthorize("@ps.hasPermission()")
    @PostMapping
    public ResponseResult addMenu(@RequestBody Menu menu){
        return menuServiceImpl.addMenu(menu);
    }

    @GetMapping("/{menuId}")
    public ResponseResult selectMenu(@PathVariable("menuId") Long menuId){
        return menuServiceImpl.selectMenu(menuId);
    }
    @PreAuthorize("@ps.hasPermission()")
    @PutMapping
    public ResponseResult updateMenu(@RequestBody Menu menu){
        return menuServiceImpl.updateMenu(menu);
    }
    @PreAuthorize("@ps.hasPermission()")
    @DeleteMapping("/{menuId}")
    public ResponseResult deleteMenu(@PathVariable("menuId") Long menuId){
        return menuServiceImpl.deleteMenu(menuId);
    }

    @GetMapping("/treeselect")
    public ResponseResult addUserMenu(){
        return menuServiceImpl.getMenuTree();
    }

    @GetMapping("/roleMenuTreeselect/{roleId}")
    public ResponseResult selectMenuById(@PathVariable("roleId") Long roleId){
        return menuServiceImpl.getMenuTree(roleId);
    }
}
